"use strict";
{
    // 声明函数
    function createArray(count, value) {
        //声明空数组
        let arr = [];
        //循环
        for (let i = 0; i < count; i++) {
            arr.push(value);
        }
        //返回数组
        return arr;
    }
    //调用函数
    let result = createArray(3, "abc");
    // result[0].//这里没有提示
    // result[0].toFixed(2);//没有错误提醒
}
{
    // 泛型函数
    // 声明函数    T 泛型参数, 一般大写, 常用的泛型参数有 T V K R
    function createArray(count, value) {
        //声明空数组
        let arr = [];
        //循环
        for (let i = 0; i < count; i++) {
            arr.push(value);
        }
        //返回数组
        return arr;
    }
    //调用函数
    // let result = createArray<string>(3, 'love');
    let result = createArray(3, "123");
    //操作元素
    // result[0].split('-')//有代码提示
    // result[0].toFixed(2);// 这里有报错提醒
}
{
    // 多个泛型参数  a,b  => [a, b]
    function createArray(a, b) {
        return [a, b];
    }
    //调用函数, 传入泛型参数的类型
    // let result = createArray<string, number>('a', 10);
    //泛型参数可以省略
    let result = createArray("aaa", 10);
    // result[0].  //代码提示
    // result[1].slice();//报错提醒
}
{
    //第一个响应对象
    let response = {
        status: 200,
        headers: {},
        data: {
            id: 1,
            name: "西游记",
            price: 28,
        },
    };
    //第二个响应对象
    let response2 = {
        status: 200,
        headers: {},
        data: {
            id: 20,
            title: "大话西游",
            director: "周星驰",
        },
    };
}
{
    //有一个对象
    let response = {
        status: 200,
        statusText: "OK",
        headers: {},
        data: {
            id: 1,
            title: "9号电动车 - N70C",
            price: 2999,
        },
    };
    let response2 = {
        status: 200,
        statusText: "OK",
        headers: {},
        data: {
            id: 20,
            name: "幻城",
            author: "小四",
        },
    };
    let response3 = {
        status: 200,
        statusText: "OK",
        headers: {},
        data: {
            id: 20,
            username: "zhangsan",
            age: 28,
        },
    };
}
{
    //有一个对象   0000   0001   0010    0020   0201
    let response = {
        status: 200,
        statusText: "OK",
        headers: {},
        data: {
            code: 2000,
            msg: '请求成功',
            data: {
                id: 1,
                title: "9号电动车 - N70C",
                price: 2999,
            }
        },
    };
    let response2 = {
        status: 200,
        statusText: "OK",
        headers: {},
        data: {
            code: 2000,
            msg: '请求成功',
            data: {
                id: 20,
                name: '旅行',
                singer: '许巍'
            }
        },
    };
}
{
    // 泛型类
    class Container {
        //初始化
        constructor(arr) {
            //属性
            this.container = [];
            this.container = arr;
        }
        //添加
        add(arg) {
            this.container.push(arg);
        }
    }
    //实例化对象
    let c = new Container([1, 2]);
    let c2 = new Container(['a', 'b', 'c']);
    let c3 = new Container([{ id: 1, name: '水浒传', price: 19.9 }]);
    c3.add({ id: 2, name: '红楼梦', price: 29.9 });
}
{
    //声明一个函数, 返回参数值的长度属性
    function getLength(arg) {
        return arg.length;
    }
    getLength('abc');
    getLength([1, 2, 3, 4, 5]);
    // getLength<number>(123);
}
